package com.dfrz.controller;

import com.dfrz.common.ResultEnum;
import com.dfrz.entity.Comment;
import com.dfrz.entity.Result;
import com.dfrz.service.CommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author 29877
 */
@RestController
public class CommentController {
    @Resource
    CommentService commentService;
    @GetMapping("/getallcomment")
    public Result getAllCommentByVid(Integer videoid){
        Map<String,Object> commentSort=commentService.findAllCommentbyVideoId(videoid);
        return Result.success(commentSort);
    }

    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){
        LocalDateTime lDT=LocalDateTime.now();
        LocalDateTime Now=LocalDateTime.of(lDT.getYear(),lDT.getMonth(),lDT.getDayOfMonth(),lDT.getHour(),lDT.getMinute(),lDT.getSecond());
        String now=Now.toString().replace("T"," ");
        comment.setCommentTime(now);
        commentService.addComment(comment);
        return Result.success(ResultEnum.SUCCESS);
    }
}